const uiFormControls = require('../ui-form/ui-form-controls');
// index.js
Component({
    behaviors: [uiFormControls],
    options: {
        addGlobalClass: true,
        multipleSlots: true
    },
    relations: {
        '../ui-form/index': {
            type: 'ancestor', // 关联的目标节点应为祖先节点
        }
    },
    /**
     * 组件的属性列表
     */
    properties: {
        disabled: {
            type: Boolean,
            value: false
        },
        validate: {
            type: Boolean,
            value: false
        },
        labelWidth: {
            type: Number,
            value: 0
        },
        label: {
            type: String,
            value: ''
        },
        name: {
            type: String,
            value: ''
        },
        value: {
            type: Boolean,
            value: false
        },
        checkedPlaceHolder: {
            type: String,
            value: ''
        },
        unCheckedPlaceHolder: {
            type: String,
            value: ''
        },
        ifSlot: {
            type: Boolean,
            value: false
        },
        border: {
            type: Boolean,
            value: true
        },
        // 选项框左侧标签
        boxLabel: {
            type: String,
            value: ''
        }
    },
    lifetimes: {
        attached: function () {

        }
    },
    /**
     * 组件的初始数据
     */
    data: {
        eventName: 'change',
    },

    /**
     * 组件的方法列表
     */
    methods: {
        validate: function (value) {
            return true;
        },
        checkboxTap: function (e) {
            const that = this;
            if (that.data.disabled) { return; }
            this.setData({
                value: !that.data.value
            }, () => {
                that.dataChange({name: that.data.name, value: that.data.value});
            })
        },
        dataChange: function (e) {
            const that = this;
            that.triggerEvent( that.data.eventName , e);
        }
    }
})